package org.training.apr.service.impl;

import org.training.apr.dao.DaoFactory;
import org.training.apr.dao.fake.FakeDaoFactory;
import org.training.apr.service.EnterpriseService;
import org.training.apr.service.ServiceFactory;
import org.training.apr.service.UserService;

public final class DefaultServiceFactory implements ServiceFactory {
	private static DaoFactory daoFactory = new FakeDaoFactory();
	
	private static final ServiceFactory instance = new DefaultServiceFactory();
	
	public static ServiceFactory getInstance() {
		return instance;
	}
	
	public static void setDaoFactory(DaoFactory daoFactory) {
		DefaultServiceFactory.daoFactory = daoFactory;
	}

	public EnterpriseService createEnterpriseService() {		
		return new EnterpriseServiceImpl(daoFactory.createEnterpriseDao());
	}

	public UserService createUserService() {
		return new UserServiceImpl(daoFactory.createUserDao());
	}

	public DaoFactory getDaoFactory() {
		return daoFactory;
	}
}
